local Lua__tianbao = fk.CreateSkill {
  name = "Lua__tianbao",
}

Fk:loadTranslationTable {
  ["Lua__tianbao"] = "舔包",
  ["$Lua__tianbao1"] = "江畔何时初见雪，江雪何年唤映人。",
  ["$Lua__tianbao2"] = "大仇未报，还不能这样死去。",
  ["$Lua__tianbao3"] = "清寒向来不喜欢失败。",
  [":Lua__tianbao"] = "回合技，当有玩家获得牌时，你获得其手牌区中的所有基本牌，若此时其的手牌数小于4，则摸至4。",
  ["@@tianbao-turn"] = "舔包",
}

Lua__tianbao:addEffect(fk.AfterCardsMove, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(Lua__tianbao.name) or player:usedSkillTimes(Lua__tianbao.name, Player.HistoryTurn) == 1 then return false end
    for _, move in ipairs(data) do
      if move.to and move.to ~= player and move.toArea == Player.Hand then
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = Lua__tianbao.name, })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 找到获得牌的角色
    local targets = {}
    for _, move in ipairs(data) do
      if move.to and move.to ~= player and move.toArea == Player.Hand then
        table.insertIfNeed(targets, move.to)
      end
    end
    for _, pid in ipairs(targets) do
      local target = pid
      -- 获取目标手牌中的基本牌
      local basic_cards = {}
      for _, id in ipairs(target:getCardIds(Player.Hand)) do
        local card = Fk:getCardById(id)
        if card.type == Card.TypeBasic then
          table.insert(basic_cards, id)
        end
      end
      -- 获得所有基本牌
      if #basic_cards > 0 then
        room:obtainCard(player, basic_cards, false, fk.ReasonPrey)
        if #target:getCardIds(Player.Hand) < 4 then
          local draw_num = 4 - #target:getCardIds(Player.Hand)
          target:drawCards(draw_num, Lua__tianbao.name)
        end
      end
    end
  end,
})

return Lua__tianbao
